package com.xingxue.controller;

import com.xingxue.service.RecruitmentInfoService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * @author zhangguangxin at 2018/10/24 22:44
 */
@Controller
@RequestMapping("recruitmentInfo")
public class RecruitmentInfoController {

    @Autowired
    RecruitmentInfoService recruitmentInfoService;


    @RequestMapping(value = "/search")
    public ModelAndView search(){
        ModelAndView mv = new ModelAndView();
        List<HashMap<String,Object>> recruitment = this.recruitmentInfoService.search();
        mv.addObject("recruitment",recruitment);
        mv.setViewName("recruitmentInfo");
        return mv;
    }

    @RequestMapping(value = "/add")
    public ModelAndView add(@RequestParam HashMap<String,Object> param){
        this.recruitmentInfoService.add(param);
        return new ModelAndView("redirect:search.do");
    }

    @RequestMapping(value = "/updateById")
    public ModelAndView updateById(@RequestParam HashMap<String,Object> param){
        this.recruitmentInfoService.updateByID(param);
        return new ModelAndView("redirect:search.do");
    }

    @RequestMapping(value = "/deleteById")
    public ModelAndView deleteById(@RequestParam HashMap<String,Object> param){
        this.recruitmentInfoService.deleteByID(param);
        return new ModelAndView("redirect:search.do");
    }

    @RequestMapping(value = "/deleteCheckedById")
    public ModelAndView deleteById(@RequestParam String num){
        List<String> param = Arrays.asList(num.split(","));
        this.recruitmentInfoService.deleteCheckedByID(param);
        return new ModelAndView("redirect:search.do");
    }
}
